﻿using APIBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Models;
using System;

namespace APIUI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        public UserController(UserBLL bLL,ILogger<UserController> logger)
        {
            BLL = bLL;
            Logger = logger;
        }

        public UserBLL BLL { get; }
        public ILogger<UserController> Logger { get; }

        [HttpPost("AddUser")]
        public int AddUser(User user)
        {
            return BLL.AddUser(user);
        }

        [HttpGet("GetUser")]
        public User GetUser(string username, string pwd)
        {
            //登录成功时记录日志，日志内容是登录名称+当前系统时间
            User u= BLL.GetUser(username, pwd);
            if (u.Id > 0)
            {
                Logger.LogInformation($"6666666{username}:{DateTime.Now.ToString("yyyy-MM-dd")}");
                Logger.LogDebug("6666666");
                Logger.LogError("6666666");
                Logger.LogWarning("6666666");
            }
            return u;
        }

    }
}
